package com.swim.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.OneToOne;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;
import com.swim.session.Util;

@Entity
@Table(name="Collaboration")
public class Collaboration implements Serializable, Comparable<Collaboration>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 2753520214635023787L;

	@Id
	@Column(name="id", nullable=false)
	@GeneratedValue
	private int id;
	
	@Column(name="date", nullable=false)
	private String date;
	
	@ManyToOne
	@JoinColumn(name="emailFrom")
	private RegisteredUser emailFrom;
	
	@ManyToOne
	@JoinColumn(name="emailTo")
	private RegisteredUser emailTo;
	
	@OneToOne//(mappedBy="id" , cascade=CascadeType.ALL)
	@JoinColumn(name = "idFeedback")
	private Feedback idFeedback;
	
	@ManyToOne
	@JoinColumn(name="idSkill")
	private Skill idSkill;
	
	public Collaboration() {}
	
	public Collaboration(String date,  RegisteredUser offering, RegisteredUser receiving, 
			Skill idSkill, Feedback idFeedback){
		setDate(date);
		setEmailFrom(offering);
		setEmailTo(receiving);
		setIdSkill(idSkill);
		setIdFeedback(idFeedback);
	}
	
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return the date
	 */
	public String getDate() {
		return date;
	}

	/**
	 * @param date the date to set
	 */
	public void setDate(String date) {
		this.date = date;
	}

	/**
	 * @return the id of the Feedback
	 */
	public Feedback getIdFeedback() {
		return idFeedback;
	}

	/**
	 * @param idFeedback the id of the Feedback to set
	 */
	public void setIdFeedback(Feedback idFeedback) {
		this.idFeedback = idFeedback;
	}

	/**
	 * @return the id of the Skill
	 */
	public Skill getIdSkill() {
		return idSkill;
	}

	/**
	 * @param idSkill the id of the skill to set
	 */
	public void setIdSkill(Skill idSkill) {
		this.idSkill = idSkill;
	}

	/**
	 * @return the email of the applicant
	 */
	public RegisteredUser getEmailFrom() {
		return emailFrom;
	}

	/**
	 * @param emailFrom the email of the applicant to set
	 */
	public void setEmailFrom(RegisteredUser emailFrom) {
		this.emailFrom = emailFrom;
	}

	/**
	 * @return the email of the recipient
	 */
	public RegisteredUser getEmailTo() {
		return emailTo;
	}

	/**
	 * @param emailTo the the email of the recipient to set
	 */
	public void setEmailTo(RegisteredUser emailTo) {
		this.emailTo = emailTo;
	}

	public int compareTo(Collaboration c) {
		 
		if(c == null) {
			return 1;
		}
		if(c.getId() == this.id) {
			return 0;
		}
		if(Util.compareDate(this.date, c.date) != 0) {
			return Util.compareDate(this.date, c.date);
		}
		return c.getId() > this.id ? -1:1;
	}
}
